﻿/*
 * Author: Mattan360
 * Contributors:
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Irrlicht.Net
{
    public class OSOperator : ReferenceCounted
    {
        #region PInvoke
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool OSOperator_CopyToClipboard(IntPtr scmgr,
            [MarshalAs(UnmanagedType.AnsiBStr)]
            string text);
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern IntPtr OSOperator_GetTextFromClipboard(IntPtr scmgr);

        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern IntPtr OSOperator_GetOperationSystemVersion(IntPtr scmgr);
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool OSOperator_GetProcessorSpeedMHz(IntPtr scmgr, ref uint speed);
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool OSOperator_GetSystemMemory(IntPtr scmgr, ref uint total, ref uint avil);
        #endregion

        public OSOperator(IntPtr pointer)
            : base(pointer)
        { }

        public string Clipboard
        {
            get
            {
                IntPtr point = OSOperator_GetTextFromClipboard(pointer);
                return Marshal.PtrToStringAnsi(point);
            }
            set
            {
                OSOperator_CopyToClipboard(pointer, value);
            }
        }
        public string OperationSystemVersion
        {
            get
            {
                IntPtr point = OSOperator_GetOperationSystemVersion(pointer);
                return Marshal.PtrToStringBSTR(point);
            }
        }
        public uint ProcessorSpeedMHz
        {
            get
            {
                uint speed = 0;
                OSOperator_GetProcessorSpeedMHz(pointer, ref speed);
                return speed;
            }
        }
        public SystemMemory SystemMemory
        {
            get
            {
                SystemMemory memory = new SystemMemory();
                OSOperator_GetSystemMemory(pointer, ref memory.total, ref memory.available);
                return memory;
            }
        }
    }
}
